package io;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamReadFileDemo {

    public static void main(String[] args) {

    }

    public static void main2(String[] args) {
        try(InputStream inputStream=new FileInputStream("./test.txt")) {
            while(true) {
                byte[] buffer = new byte[1024];
                int n = inputStream.read(buffer);
                if (n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("0x%x\n", buffer[i]);
                }
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
    public static void main1(String[] args) {
        try(InputStream inputStream=new FileInputStream("./test.txt")) {
            while(true) {
                int b=inputStream.read();
//                System.out.println(b);//
                if(b==-1) {
                    break;//读到文件末尾了
                }
                //表示字节,更习惯使用十六进制来打印.
                System.out.printf("0x%x\n",b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
